# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=pycairo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-cairo" "${MINGW_PACKAGE_PREFIX}-python3-cairo")
pkgver=1.17.0
pkgrel=1
pkgdesc="Python bindings for the cairo graphics library (mingw-w64)"
url="https://pycairo.readthedocs.io"
arch=('any')
license=('LGPL' 'MPL')
depends=("${MINGW_PACKAGE_PREFIX}-cairo")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest"
              "${MINGW_PACKAGE_PREFIX}-python2-pytest")
source=(https://github.com/pygobject/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('cdd4d1d357325dec3a21720b85d273408ef83da5f15c184f2eff3212ff236b9f')

prepare() {
  cd "${srcdir}"
  rm -rf python2-build python3-build
  cp -r ${_realname}-${pkgver} python2-build
  cp -r ${_realname}-${pkgver} python3-build
}

build() {
  cd "${srcdir}"
  for builddir in python{2,3}-build; do
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py build
    popd
  done
}

check() {
  cd "${srcdir}"
  for builddir in python{2,3}-build; do
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py test
    popd
  done
}

package_python2-cairo() {
  depends+=("${MINGW_PACKAGE_PREFIX}-python2")
  cd "${srcdir}/python2-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 COPYING* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-cairo"
}

package_python3-cairo() {
  depends+=("${MINGW_PACKAGE_PREFIX}-python3")
  cd "${srcdir}/python3-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 COPYING* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-cairo"
}

package_mingw-w64-i686-python2-cairo() {
  package_python2-cairo
}

package_mingw-w64-i686-python3-cairo() {
  package_python3-cairo
}

package_mingw-w64-x86_64-python2-cairo() {
  package_python2-cairo
}

package_mingw-w64-x86_64-python3-cairo() {
  package_python3-cairo
}
